﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;

namespace BreezeEditor
{
    public static class BreezeEditorExtensions
    {
        public static MvcHtmlString BreezeEditor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
        {
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);

            var builder = new TagBuilder("input");
            builder.Attributes["type"] = "text";
            System.Reflection.PropertyInfo p = typeof(TModel).GetProperty(metadata.PropertyName);
            Type t = p.PropertyType;
            builder.Attributes["value"] = t.ToString();
            builder.Attributes["name"] = metadata.PropertyName;
            
            MvcHtmlString returnStr = MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing));
            
            return returnStr;
        }
    }
}